package com.olympia.myapp.custom;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.olympia.myapp.R;

public class Dialog_Regis extends Dialog implements OnClickListener {
	Activity activity;
	ProcessDialogRegis processDialogMove;
	EditText edtMail;
	EditText edtPass;
	// EditText edtPassConfirm;
	Button btnRegis;
	ImageView btnClose;
	public ProgressBar progress;

	/**
	 * 
	 * @param context
	 */
	public Dialog_Regis(Context context, ProcessDialogRegis process) {
		super(context);
		activity = (Activity) context;
		/** 'Window.FEATURE_NO_TITLE' - Used to hide the title */
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		/** Design the dialog in main.xml file */
		setContentView(R.layout.dialog_regis);
		processDialogMove = process;

		progress = (ProgressBar) findViewById(R.id.progress_dg);
		btnClose = (ImageView) findViewById(R.id.dg_iconClose);
		btnRegis = (Button) findViewById(R.id.dg_btnRegis);
		edtMail = (EditText) findViewById(R.id.edt_mail);
		edtPass = (EditText) findViewById(R.id.edt_pass);
		// edtPassConfirm = (EditText) findViewById(R.id.edt_cfPass);
		btnRegis.setOnClickListener(this);
		btnClose.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		if (v == btnClose) {
			dismiss();
		} else if (v == btnRegis) {
			String mail = edtMail.getText().toString();
			String pass = edtPass.getText().toString();
			// String cfPass = edtPassConfirm.getText().toString();

			if (validate(mail, pass)) {
				progress.setVisibility(View.VISIBLE);
				processDialogMove.click_Ok(mail, pass);
			} else {
				if (mail.length() <= 0)
					edtMail.setError("Email đăng ký không hợp lệ, hoặc email này đã được sử dụng.");
				else if (pass.length() <= 0)
					edtPass.setError("Mật khẩu không hợp lệ, xin vui lòng kiểm tra lại.");
				// else
				// edtPassConfirm.setError("Xác nhận lại mật khẩu không đúng");
			}
		}
	}

	private boolean validate(String mail, String pass) {
		return mail.length() > 0 && pass.length() > 0;
	}

	public static abstract class ProcessDialogRegis {
		public abstract void click_Ok(String mail, String pass);
	}
}
